{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 项目模板\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 项目介绍\n",
    "\n",
    "- 项目介绍\n",
    "\n",
    "  本项目是一个练习项目，主要练习了 python 的语法，以及 jupyter notebook 的使用。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 调用命令行\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "bash_exec_str = os.system(\"bash -c ls -a\")\n",
    "print(f\"bash_exec_str = [{bash_exec_str}]\")\n",
    "nu_exec_str = os.system(\"nu -c ls\")\n",
    "print(f\"nu_exec_str = [{nu_exec_str}]\")\n",
    "zsh_exec_str = os.system(\"zsh -c ls\")\n",
    "print(f\"zsh_exec_str = [{zsh_exec_str}]\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- maven 项目\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "# maven clean\n",
    "os.system(\"bash -c 'mvn clean'\")\n",
    "os.system(\"bash -c 'mvn package -DskipTests'\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 注释掉代码中的指定行\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 给指定文件的指定行添加一个指定的注释符号\n",
    "def add_comment(file_path, line_number, comment_symbol):\n",
    "    with open(file_path, 'r') as f:\n",
    "        lines = f.readlines()\n",
    "\n",
    "    if line_number < 1 or line_number > len(lines):\n",
    "        raise ValueError(\"Invalid line number\")\n",
    "\n",
    "    lines[line_number - 1] = comment_symbol + lines[line_number - 1]\n",
    "\n",
    "    with open(file_path, 'w') as f:\n",
    "        f.writelines(lines)\n",
    "        print(\"Comment added successfully!\")\n",
    "        return True\n",
    "\n",
    "pwd = %pwd\n",
    "print(pwd)\n",
    "add_comment(f\"{pwd}/api.py\", 3, \"#\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 取消掉注释"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 取消指定文件的指定行的指定注释符号的注释\n",
    "def uncomment(file_path, line_number, comment_symbol):\n",
    "    with open(file_path, 'r') as file:\n",
    "        lines = file.readlines()\n",
    "\n",
    "    if line_number < 1 or line_number > len(lines):\n",
    "        print(\"Invalid line number\")\n",
    "        return\n",
    "\n",
    "    lines[line_number - 1] = lines[line_number - 1].replace(comment_symbol, '')\n",
    "\n",
    "    with open(file_path, 'w') as file:\n",
    "        file.writelines(lines)\n",
    "        print(\"Comment removed successfully\")\n",
    "        return\n",
    "\n",
    "pwd = %pwd\n",
    "print(pwd)\n",
    "uncomment(f\"{pwd}/api.py\", 3, \"#\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
